package com.gxa.ribbon.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @author LENOVO
 */
@Configuration
public class RibbonConfiguration {

    /**
     * IRule接口负责给负载均衡描述规则
     *
     * @return iRule 返回一个负载均衡的规则
     */
    @Bean
    IRule getRule() {
        IRule iRule = new RandomRule();
        return iRule;
    }

    /**
     * 开启负载均衡功能
     *
     * @return
     * @LoadBalanced注解表明这个restRemplate开启负载均衡的功能
     */
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

}
